﻿using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
using XjjXmm.Infrastructure.Common;

namespace Blog.API.Filter
{

    public class MvcActionFilter : IAsyncResultFilter
    {
        //  private readonly IWebHostEnvironment _env;
        public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {
            if (context.Result is ObjectResult objectResult)
            {
                var statusCode = objectResult.StatusCode ?? context.HttpContext.Response.StatusCode;

                //if (!_options.NoWrapStatusCode.Any(s => s == statusCode))
                //{
                //var wrappContext = new DataWrapperContext(context.Result,
                //                                          context.HttpContext,
                //                                          //_options,
                //                                          context.ActionDescriptor);

                // var wrappedData = _wrapperExecutor.WrapSuccesfullysResult(objectResult.Value, wrappContext);
                objectResult.Value = new ResponseModel<object>(objectResult?.Value);
                // objectResult.DeclaredType = wrappedData.GetType();
                //}
            }

            await next();


        }



    }


}
